﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using Net.Chirash.Twitter.TwitterClient;
using Net.Chirash.Twitter.TweetZone.WindowComponents.ViewModels;
using Net.Chirash.Twitter.TwitterDatabase;

namespace Net.Chirash.Twitter.TweetZone.WindowComponents.Containers
{
    /// <summary>
    /// TimelineContainer.xaml の相互作用ロジック
    /// </summary>
    public partial class TimelineContainer : Container
    {
        #region Constructors

        public TimelineContainer(TimelineContainerViewModel vm)
            : base(vm)
        {
            InitializeComponent();
        }

        public TimelineContainer(TimelineTypes types)
            : this(new TimelineContainerViewModel(types))
        { }

        public TimelineContainer(TimelineTypes types, User user)
            : this(new TimelineContainerViewModel(types, user))
        { }

        //for wpf
        public TimelineContainer()
            : this(new TimelineContainerViewModel())
        { }

        #endregion

        #region Public Methods

        public override string ToString()
        {
            return Enum.GetName(typeof(TimelineTypes), (ViewModel as TimelineContainerViewModel).TimelineType);
        }

        #endregion


        #region Private Methods and Properties

        private void TimelineListBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (e.VerticalChange > 0.0)
            {
                double remains = e.ExtentHeight - (e.ViewportHeight + e.VerticalOffset);
                if (0.0 <= remains && remains <= 4.0)
                {
                    (ViewModel as TimelineContainerViewModel ).PagingStart();
                }
            }
        }

        //private void CloseErrorPresent_Click(object sender, RoutedEventArgs e)
        //{
        //    ErrorPresentGrid.Visibility = System.Windows.Visibility.Collapsed;
        //    ViewModel.LastErrorMessage.Provider = null;
        //}

        //private void ErrorTextBlock_TargetUpdated(object sender, DataTransferEventArgs e)
        //{
        //    if (ErrorTextBlock.Text == "")
        //    {
        //        ErrorPresentGrid.Visibility = System.Windows.Visibility.Collapsed;
        //    }
        //    else
        //    {
        //        ErrorPresentGrid.Visibility = System.Windows.Visibility.Visible;
        //    }

        //}

        #endregion

    }

}
